﻿using mscook.core;
using mscook.core.components;
using mscook.core.domain;
using mscook.core.repositories;
using mscook.core.services;
using mscook.mvc.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace mscook.mvc.Controllers
{
    public class HomeController : BaseController
    {
        private ISlideRepository iSlideRepo;
        private ILoginUserService iLoginUserService;
        private IMagazineService iMagazineService;
        private ICookBookService iCookBookService;
        private IMaterialService iMaterialService;
        private IChefService iChefService;
        private IHotelService iHotelService;
        private IFeatureRepository iFeatureRepository;
        private IResourceTypeRepository iResourceTypeRepository = UnityHelper.UnityToT<IResourceTypeRepository>();
        private IAboutUsService iAboutUsService;
        IImageSettingFactory iImageSettingFactory;

        public HomeController(IFeatureRepository iFeatureRepository, IActionBonusSettingService actionBonusSettingService, IResourceBonusSettingService resourceBonusSettingService, ILoginUserService loginUserService,
            ISlideRepository iSlideRepository, IImageSettingFactory iImageSettingFactory, IMagazineService iMagazineService, ICookBookService iCookBookService, IMaterialService iMaterialService,
            IHotelService iHotelService, IChefService iChefService, IAboutUsService iAboutUsService)
            : base(actionBonusSettingService, resourceBonusSettingService, loginUserService)
        {
            this.iLoginUserService = loginUserService;
            this.iSlideRepo = iSlideRepository;
            this.iImageSettingFactory = iImageSettingFactory;
            this.iMagazineService = iMagazineService;
            this.iFeatureRepository = iFeatureRepository;
            this.iCookBookService = iCookBookService;
            this.iMaterialService = iMaterialService;
            this.iHotelService = iHotelService;
            this.iChefService = iChefService;
            this.iAboutUsService = iAboutUsService;
        }
        public ActionResult Index()
        {
            long total = 0;
            HomeModel HomeModel = new HomeModel();

          //  IList<ResourceType> cookBookTypes = iResourceTypeRepository.GetTypeByCategory(PurchasedCategory.CookBook);


            HomeModel.SlideList = iSlideRepo.SelectPageList(0,7,out total);
            HomeModel.MagazineList = iMagazineService.SelectPageList(0,3,out total);
            HomeModel.CookBookList = iCookBookService.SelectPageList(0,7,out total);//2013-12-05 Lampard暂时全部取出,根据名字查询
            HomeModel.MaterialList = iMaterialService.SelectPageList(0,10,out total);
            HomeModel.FeatureList = iFeatureRepository.SelectPageList(0,5,out total);
            HomeModel.HotelList = iHotelService.GetLimitPartner(0,6);
            HomeModel.ChefList = iChefService.SelectPageList(0,6,out total); ;
            HomeModel.CookBooResourceTypes = iResourceTypeRepository.GetHotChildTypesByLimit(PurchasedCategory.CookBook.ToString(),0,12,out total);
            HomeModel.MaterialResourceTypes = iResourceTypeRepository.GetHotChildTypesByLimit(PurchasedCategory.Material.ToString(), 0, 6, out total).OrderBy(o => o.Name.Length).ToList();

            HomeModel.LoginUser = CurrentUser;
            InitNavBar();
            return View(HomeModel);
        }
        public ActionResult SelectImageSetting()
        {
            IList<ImageSettingFactory.ImageSettingSection> slideSettings =
               iImageSettingFactory.SelectSections();
            return Json(slideSettings, JsonRequestBehavior.AllowGet);
        }

        public ActionResult SelectMagazines()
        {
            IList<Magazine> Magazines = iMagazineService.SelectAll();
            return Json(Magazines, JsonRequestBehavior.AllowGet);
        }

    }
}
